<?php

class Application_Form_ChangePass extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post')
        	->setAttrib('id', 'changePassForm');
        
        $this->clearDecorators();
        $this->addElementPrefixPath('SubfolderAccessManager_Validate', 'SubfolderAccessManager/Validate/', 'validate');
        
        $decorators = array(
        		array('ViewHelper'),
        		array('Errors'),
        		array('Label', array('requiredSuffix' => ' *', 'class' => 'leftalign')),
        		array('HtmlTag', array('tag' => 'li')),
        );
        
        $currentPass = $this->addElement('password', 'currentPass',
        		array('label' => 'Current Password'));
        $currentPass = $this->getElement('currentPass')
        	->addValidator('PasswordIdenticalToCurrent')
        	->setRequired(true)
        	->addFilter('StringTrim');
        $currentPass->setDecorators($decorators);
        
        $newPass = $this->addElement('password', 'newPass',
        		array('label' => 'New Password'));
        $newPass = $this->getElement('newPass')
        		->addValidator('stringLength', true, array(8))
        		->addValidator('PasswordNotIdenticalToCurrent')
        		->setRequired(true)
        		->addFilter('StringTrim');
        $newPass->getValidator('stringLength')->setMessage('Your password is too short');
        $newPass->getValidator('PasswordNotIdenticalToCurrent')->setMessage('New password is the same as the current one');
        $newPass->setDecorators($decorators);
        
        $confirmPass = $this->addElement('password', 'confirmPass',
        		array('label' => 'Confirm Password'));
        $confirmPass = $this->getElement('confirmPass')
        	->addValidator('Identical', false, array('token' => 'newPass'))
        	->setRequired(true)
        	->addFilter('StringTrim');
        $confirmPass->getValidator('Identical')
        	->setMessage('Password does not match');
        $confirmPass->setDecorators($decorators);
        
        $submit = $this->addElement('submit', 'save',
        		array('label' => 'Save'));
        $submit = $this->getElement('save')
       		->setDecorators(array(
        		array('ViewHelper'),
        ));
        
        $cancel = $this->addElement('submit', 'cancel',
        		array('label' => 'Cancel'));
        $cancel = $this->getElement('cancel')
        	->setDecorators(array(
        		array('ViewHelper'),
        ));
        
        $this->addDisplayGroup(array('save', 'cancel'), 'submit_buttons',
        		array('disableLoadDefaultDecorators' => true));
        $submitButtons = $this->getDisplayGroup('submit_buttons');
        $submitButtons->addDecorators(array(
        		array('FormElements', 'Form'),
        		array('HtmlTag', array('tag' => 'li', 'class' => 'submit')),
        ));
        
        $this->setDecorators(array(
        		'FormElements',
        		array('HtmlTag', array('tag' => 'ul')),
        		array(array('DivTag' => 'HtmlTag'),
        				array('tag' => 'div', 'id' => 'changePassDiv')),
        		'Form'
        ));
    }
}

